﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SubForum.Web.Services.Interfaces;
using SubForum.ObjectModel.Users;
using System.Web.Security;

namespace SubForum.Web.Services
{
    public class SubForumAdminService: ISubForumAdminService
    {
        #region ISubForumAdminService Members

        public void CreateUserProfile(SubForum.ObjectModel.Users.MemberUser userToCreate)
        {
            DataAccessManager.GetDataAccessService().InsertUserProfile(new List<MemberUser>() { userToCreate });
        }

        public void UpdateUserProfile(SubForum.ObjectModel.Users.MemberUser oldUserProfile, SubForum.ObjectModel.Users.MemberUser updatedUserProfile)
        {
            throw new NotImplementedException();
        }

        public void DeleteUserProfile(SubForum.ObjectModel.Users.MemberUser userProfileToDelete)
        {
            throw new NotImplementedException();
        }

        public UserList<MemberUser> GetAllUserProfiles()
        {
            UserList<MemberUser> userList = new UserList<MemberUser>();
            
            userList.AddRange(DataAccessManager.GetDataAccessService().GetAllMemberProfiles());

            return userList;
        }

        public MemberUser GetUserProfileByUserName(string userName)
        {
            MemberUser mu = DataAccessManager.GetDataAccessService().GetUserProfileByUserName(userName).FirstOrDefault();

            if (mu != null)
            {
                mu.MembershipUser = Membership.Provider.GetUser(userName, false);

            }

            return mu;
        }

        #endregion
    }
}
